<template>
  <div>
    <!-- 鼠标感应区域，始终存在 -->
    <div
      class="trigger-zone"
      @mouseenter="expand"
    ></div>

    <!-- 侧边栏 -->
    <div
      class="navbar"
      :class="{ 'navbar-hidden': !isExpanded }"
      @mouseleave="collapse"
    >
      <div class="nav-content">
        <el-menu
          :default-active="activeIndex"
          class="nav-menu"
          :collapse="!isExpanded"
          @select="handleSelect"
        >
          <el-menu-item index="1" class="menu-item">
            <i class="el-icon-s-home"></i>
            <span class="title">智慧大屏</span>
          </el-menu-item>
        </el-menu>

        <div class="navbar-footer" :class="{ 'footer-collapsed': !isExpanded }">
          <el-button
            icon="el-icon-switch-button"
            class="logout-btn"
            @click="logout"
          >
            <span v-show="isExpanded">退出登录</span>
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
export default {
  name: 'Navbar',
  data() {
    return {
      activeIndex: '1',
      isExpanded: false,
    }
  },
  methods: {
    expand() {
      this.isExpanded = true
    },
    collapse() {
      this.isExpanded = false
    },
    handleSelect(key) {
      this.activeIndex = key;
      this.$router.push('/');
    },
    logout() {
      localStorage.removeItem('coin-token');
      this.$router.push('/user');
    }
  }
}
</script>


<style scoped>
.trigger-zone {
  position: fixed;
  top: 0;
  left: 0;
  width: 10px;     /* 感应宽度，可调 */
  height: 100vh;
  z-index: 1100;   /* 在最上层 */
  background: transparent; /* 不可见但可触发 hover */
}

.navbar {
  width: 200px;
  height: 100vh;
  background-color: #1a1f37;
  position: fixed;
  top: 0;
  left: 0;
  transition: left 0.3s ease;
  z-index: 1000;
  overflow: hidden;
}

.navbar-hidden {
  left: -200px; /* 完全隐藏到屏幕左侧 */
}

.nav-content {
  width: 200px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.title {
  color: #ffffff;
}
.menu-item{
  padding: 5px;
}
.nav-menu {
  flex: 1;
  border: none;
  background-color: transparent;
}
.logout-btn {
  width: 200px;
  background: transparent;
  border-color: rgba( 26, 31, 55);
  color: rgba(255, 255, 255, 0.8);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  white-space: nowrap;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  transform: translateY(-2px);
}
</style>

